package com.yzt.dynamicmodule.adapter;

import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.yzt.dynamicmodule.R;
import com.yzt.zhuju.RXingUtils;
import com.yzt.zhuju.network.entity.game.GameConversationBean;
import com.yzt.zhuju.widget.widget.ImageLoadManger;

/**
 * author : bob
 * date   : 2023/2/27
 * desc   : 游戏内的消息
 */
public class ActivityGameContentAdapter extends BaseQuickAdapter<GameConversationBean, BaseViewHolder> {

    public ActivityGameContentAdapter() {
        super(R.layout.item_game_room_conversation);
    }

    @Override
    protected void convert(BaseViewHolder holder, GameConversationBean item) {

        LinearLayout llGameEmoji = holder.findView(R.id.view_game_emoji);
        llGameEmoji.setVisibility(View.GONE);
        LinearLayout llGameImg = holder.findView(R.id.view_game_img);
        llGameImg.setVisibility(View.GONE);
        LinearLayout llGameGift = holder.findView(R.id.view_game_gift);
        llGameGift.setVisibility(View.GONE);
        LinearLayout llGamePunish = holder.findView(R.id.view_game_punish);
        llGamePunish.setVisibility(View.GONE);
        LinearLayout llGameRedPackage = holder.findView(R.id.view_red_package);
        llGameRedPackage.setVisibility(View.GONE);
        LinearLayout llGameRedPackageTip = holder.findView(R.id.view_red_package_tip);
        llGameRedPackageTip.setVisibility(View.GONE);
        LinearLayout llGameTemp = holder.findView(R.id.view_game_temp);
        llGameTemp.setVisibility(View.GONE);


        // "惩罚牌"
        if (item.getMsgType().equals("OCM:GamePunishCard")) {
            llGamePunish.setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_punish_content, item.getCardName())
                    .setText(R.id.tv_punish_user_name, item.getTargetUserNickName());
            if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                llGamePunish.setGravity(Gravity.END);
            }
        }

        // "红包"
        if (item.getMsgType().equals("OCM:GameRedPacket")) {
            llGameRedPackage.setVisibility(View.VISIBLE);
            LinearLayout llRedContainer = holder.findView(R.id.ll_red_package_container);
            holder.setText(R.id.tv_red_package_title, item.getTitle());
            if (item.isReceive()) {
                holder.setText(R.id.tv_red_package_content, "已领取");
                llRedContainer.setBackground(ContextCompat.getDrawable(getContext(), R.mipmap.icon_message_red_pkg_bg_time_out));
            } else {
                llRedContainer.setBackground(ContextCompat.getDrawable(getContext(), R.mipmap.icon_message_red_pkg_bg));
                if (item.getRedPackageType() == 1) {
                    holder.setText(R.id.tv_red_package_content, "拼手气红包");
                } else {
                    holder.setText(R.id.tv_red_package_content, item.getTargetNickName() + "的专属红包");
                }
            }
            if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                llGameRedPackage.setGravity(Gravity.END);
            }
        }

        // "红包领取通知"
        if (item.getMsgType().equals("OCM:GameRedPacketOpen")) {
            llGameRedPackageTip.setVisibility(View.VISIBLE);
            if (item.getTargetUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                holder.setText(R.id.tv_red_package_tip_content, "你领取了" + item.getSendNickName() + "的");
            } else {
                if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                    holder.setText(R.id.tv_red_package_tip_content, item.getTargetNickName() + "领取了你的");
                } else {
                    holder.setText(R.id.tv_red_package_tip_content, item.getTargetNickName() + "领取了" + item.getSendNickName() + "的");
                }
            }
        }

        // "礼物"
        if (item.getMsgType().equals("OCM:GameGift")) {
            llGameGift.setVisibility(View.VISIBLE);
            ImageView imgGift = holder.findView(R.id.img_gift_cover);
            ImageLoadManger.loadIv(getContext(), item.getGiftIcon(), imgGift);
            holder.setText(R.id.tv_gift_name, "·赠送 " + item.getGiftName() + "·")
                    .setText(R.id.tv_gift_content, item.getSendNickName() + "送礼物「" + item.getGiftName() + "」给" + item.getTargetNickName());
            if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                llGameGift.setGravity(Gravity.END);
            }
        }

        // "下一关"
        if (item.getMsgType().equals("OCM:GameGift")) {
            llGameTemp.setVisibility(View.VISIBLE);
            holder.setText(R.id.tv_temp_count, "第" + item.getCurrentMission() + "关");
            ImageView imgTemp = holder.findView(R.id.img_temp_cover);
            ImageLoadManger.loadIv(getContext(), item.getGameVideoUrl(), imgTemp);
            if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                llGameTemp.setGravity(Gravity.END);
            }
        }

        // 图片消息
        if (item.getMsgType().equals("OCM:GamePic")) {
            llGameImg.setVisibility(View.VISIBLE);
            ImageView imgPic = holder.findView(R.id.img_game_img);
            ImageLoadManger.loadIv(getContext(), item.getPicUrl(), imgPic);
            if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                llGameImg.setGravity(Gravity.END);
            }
        }

        // 文本消息
        if (item.getMsgType().equals("OCM:GamePiText")) {
            llGameEmoji.setVisibility(View.VISIBLE);
            ImageView imgEmoji = holder.findView(R.id.img_emoji);
            ImageLoadManger.loadIv(getContext(), item.getPicUrl(), imgEmoji);
            if (item.getSendUserId().equals(RXingUtils.getPersonDetail().getUserBasic().getUserId())) {
                llGameEmoji.setGravity(Gravity.END);
            }
        }
    }
}